//
//  MoreViewController.m
//  随便点
//
//  Created by MWJ on 15/3/12.
//  Copyright (c) 2015年 qfsoft. All rights reserved.
//

#import "MoreViewController.h"
#import "MainTableViewCell.h"
#import "downloadViewController.h"
#import "introduceViewController.h"
#import "updateViewController.h"
#import "helpViewController.h"
#import "AppDelegate.h"
#import "ViewController.h"

@interface MoreViewController (){
    UITableView *_tableView;
    NSMutableArray *tableViewArray;
    UIButton *BUTT;
    AppDelegate *app;
    UIAlertView *_alert;
}

@end

@implementation MoreViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.navigationItem.title=@"更多";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.hidesBackButton = YES;
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed: @"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = item;
    [self setupTableView];
    [self setupImage];
    [self setupCell];
}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)setupTableView{
    UITableView *tableView = [[UITableView alloc]init];
    CGFloat tableViewX = 20;
    CGFloat tableViewY = 170;
    CGFloat tableViewW = 280;
    CGFloat tableViewH = 250;
    _tableView= tableView;
    tableView.scrollEnabled= NO;
    tableView.backgroundColor = [UIColor clearColor];
    tableView.frame = CGRectMake(tableViewX, tableViewY, tableViewW, tableViewH);
    
    [self.view addSubview:tableView];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return tableViewArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"Cell";
    MainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[MainTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.layer.cornerRadius =5;
    cell.layer.masksToBounds = YES;
    cell.backgroundColor = [UIColor whiteColor];
    cell.textLabel.text =tableViewArray[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    MainTableViewCell *cell = (MainTableViewCell *)[self tableView:_tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:{
            downloadViewController *download = [self.storyboard instantiateViewControllerWithIdentifier:@"downVC"];
            [self.navigationController pushViewController:download animated:YES];
            break;
        }
        case 1:{
            introduceViewController *introduce = [[introduceViewController alloc]init];
            [self.navigationController pushViewController:introduce animated:YES];
            break;
        }
        case 2:{
            updateViewController *update = [[updateViewController alloc]init];
            [self.navigationController pushViewController:update animated:YES];
            break;
        }
        case 3:{
            helpViewController *help = [[helpViewController alloc]init];
            [self.navigationController pushViewController:help animated:YES];
            break;
        }
        case 4:{
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"真的要退出吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            _alert=alert;
            [alert show];
            break;
        }
            
        default:
            break;
    }
}
-(void)setupCell{
    
    self.automaticallyAdjustsScrollViewInsets=NO;
    if (tableViewArray == nil) {
        
        tableViewArray = [NSMutableArray arrayWithObjects:@"APP下载",@"功能介绍",@"版本更新",@"帮助与反馈",@"注销登录", nil];
        
        
    }
    _tableView.delegate=self;
    _tableView.dataSource=self;
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1&&alertView==_alert) {
        app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
        app._id=@"";
        ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(void)exit{
    
}
-(void)setupImage{
    UIImageView *tuBiaoImage = [[UIImageView alloc]init];
    CGFloat tuBiaoImageX = 80;
    CGFloat tuBiaoImageY = 80;
    CGFloat tuBiaoImageW = 160;
    CGFloat tuBiaoImageH = 80;
    tuBiaoImage.layer.cornerRadius =50;
    tuBiaoImage.layer.masksToBounds = YES;
    tuBiaoImage.image = [UIImage imageNamed:@"logo_small"];
    tuBiaoImage.frame = CGRectMake(tuBiaoImageX, tuBiaoImageY, tuBiaoImageW, tuBiaoImageH);
    
    [self.view addSubview:tuBiaoImage];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
